package java19_1_22;

public class Point<T> {
    private T x;
    private T y;
    //泛型方法
    public <T> void test(T t){
        System.out.println(t);
    }
    //完整的泛型方法
    public <S> S fun(S t){
        System.out.println(t);
        return t;
    }
    public static void main(String[] args) {
        //假设此时都是字符串
        Point<String> point = new Point<>();
        point.setX("北纬32");
        point.setY("东经32");
        //如果此时不小心输入错误，会有编译错误，而不是在运行时再出错

        //无需强制类型转换
        String x = point.getX();
        String y = point.getY();
    }

    public T getX() {
        return x;
    }

    public void setX(T x) {
        this.x = x;
    }

    public T getY() {
        return y;
    }

    public void setY(T y) {
        this.y = y;
    }

}
